// 获取保存在sessionStorage中的Token
let token = sessionStorage.getItem("token");
/*if (token == null) {
    layui.layer.msg('未获取到Token或已失效，请重新登录！',{icon: 0,time: 1000,end:function () {
            // 未登录返回登录页面
            window.open("/html/admin/login.html",'_top');
        }});
}*/
let authToken = "bearer " + token;

// 全局跨域地址：
let requestURL = "http://api.hk.com";
// let requestURL = "http://localhost:8081"
// let requestURL = "http://192.168.1.19:8081"
// let requestURL = "http://192.168.43.203:8081"
// 微服务路由规则 /api/服务名称
let prefix = '/api';
let userService = '/user-service';
let newsService = '/news-service';
let productService = '/product-service';
let elseService = '/else-service';
let uploadService = '/upload-service';


// 退出登录
function destroyLogin() {
    // 不需要后台交互的退出登录
    /*sessionStorage.removeItem("name");
    sessionStorage.removeItem("token");
    layui.layer.msg('已退出！', {
        icon: 0,
        time: 1000,
        end: function () {
            // 可以对父窗口进行刷新
            xadmin.father_reload();
            location.href = '/html/admin/login.html';
        }
    });*/
    // 退出登录
    // 获取登录日志ID，通过ID查询登录日志并添加退出时间
    let loginLogId = sessionStorage.getItem("loginLogId");
    $.ajax({
        type: 'get',
        url: requestURL+prefix+userService+'/admin/destroyLogin',
        headers: {"Authorization":authToken},
        data: {"loginLogId":loginLogId},
        success: function (data) {
            // console.log("退出登录"+data.message+"\n"+data.state)
            if (data.status == 200 ) {
                sessionStorage.removeItem("name");
                sessionStorage.removeItem("token");
                layui.layer.msg('已退出！', {
                    icon: 1,
                    time: 1000,
                    end: function () {
                        // 可以对父窗口进行刷新
                        // xadmin.father_reload();
                        location.href = '/html/admin/login.html';
                    }
                });
                // 未登录返回登录页面
                // window.open("/html/admin/login.html",'_top');
                return false;
            }
            layui.layer.msg('退出失败，请稍后重试！', {
                icon: 0,
                time: 1000
            });
            return false;
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            var state = XMLHttpRequest.status;
            if (state == 403) {
                layui.layer.msg('权限不足，请联系超级管理员！', {icon: 0, time: 1200});
                return false;
            }
            layui.layer.msg('请求接口异常！', {icon: 0, time: 1200});
            return false;
        }
    });

}